/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.mode;

import deatax.GameData;
import deatax.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 *
 * @author Pieman
 */
public class DominationGameMode extends GameMode {

    int goal;
    int def;

    public DominationGameMode(GameData data) {
        super(data);
        this.desc = "Domination. The first player to reach a certain score wins.";
        reqs = new String[]{"Score"};
        reqv = new String[]{"5000"};
        def = 5000;
    }

    @Override
    public void setArgs(String[] args) {
        try {
            goal = Integer.parseInt(args[1]);
        } catch (Exception ex) {
            goal = def;
        }
    }

    @Override
    public void scoreChanged(Player p, int score) {
        super.scoreChanged(p, score);
        if (score >= goal) {
            //win
        }
    }

    @Override
    public ArrayList<Player> getResultOrder() {
        ArrayList<Player> order = data.getRoster().getPlayers();
        Collections.sort(order, new ScoreOrder());
        
        
        ArrayList<Player> losers = data.getRoster().getLosers();
        for (int i = losers.size() - 1; i >= 0; --i) {
            order.add(losers.get(i));
        }
        return order;
    }
    
    private class ScoreOrder implements Comparator<Player> {

        @Override
        public int compare(Player o1, Player o2) {
            
            return o1.getTotalScore() - o2.getTotalScore();
        }
        
        
    } 
}
